<?php

require_once("config.php");
require_once("nusoap/nusoap.php");
require_once("utils.php");
require_once("Component.php");

class Account extends Component {

	var $defaultColumns;
	var $columnMappings;
		
        function __construct($proxy) {

		$this->defaultColumns = array(
                                        'name',
                                        'website',
                                        'ticker_symbol',
                                        'ownership',
                                        'industry',
                                        'account_type',
                                        'employees',
                                        'rating',
                                        'sic_code',
                                        'annual_revenue',
                                        'phone_office',
                                        'phone_fax',
                                        'phone_alternate',
                                        'email1',
                                        'billing_address_street',
                                        'billing_address_city',
                                        'billing_address_state',
                                        'billing_address_postalcode',
                                        'billing_address_country',
                                        'shipping_address_street',
                                        'shipping_address_city',
                                        'shipping_address_state',
                                        'shipping_address_postalcode',
                                        'shipping_address_country',
                                        'description',
                                        );

		$this->columnMappings = array ();


		parent::__construct("Accounts", "accounts", $proxy, $this->defaultColumns);
		
        }



	function getRecord($condition){

                $query = $this->getQueryColumns($this->defaultColumns);
                $query = str_replace('accounts.email1','email_address email1', $query);
                $query = 'select '.$query.' from accounts ';
                $query .=  ' LEFT JOIN  email_addr_bean_rel on accounts.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module=\'Accounts\' and email_addr_bean_rel.deleted=0 and email_addr_bean_rel.primary_address=1 ';
                $query .=  ' LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id ' ;
		$query .=  ' WHERE '.$condition;

                return $this->getRow($query);
        }

	function saveRecord($id, $name, $website, $ticker_symbol, $ownership,
							 $industry, $account_type, $employees, $rating, $sic_code,
							 $annual_revenue, $phone_office, $phone_fax, $phone_alternate, 
							 $email1, $billing_address_street, $billing_address_city, 
							 $billing_address_state, $billing_address_postalcode, 
							 $billing_address_country, $shipping_address_street,
							 $shipping_address_city, $shipping_address_state, 
							 $shipping_address_postalcode, $shipping_address_country, 
							 $description, $date_modified) {
		
		
			if ($id) {
				$response = $this->proxy->set_entry($this->sess, 'Accounts', 
								array(array("name" => 'id',"value" => $id),
									  array("name" => 'name',"value" => $name),
								      array("name" => 'website',"value" => $website),
            					      array("name" => 'ticker_symbol',"value" => $ticker_symbol),
									  array("name" => 'ownership',"value" => $ownership),
									  array("name" => 'industry',"value" => $industry),
									  array("name" => 'account_type',"value" => $account_type),
									  array("name" => 'employees',"value" => $employees),
									  array("name" => 'rating',"value" => $rating),
									  array("name" => 'sic_code',"value" => $sic_code),
									  array("name" => 'annual_revenue',"value" => $annual_revenue),
									  array("name" => 'phone_office',"value" => $phone_office),
									  array("name" => 'phone_fax',"value" => $phone_fax),
									  array("name" => 'phone_alternate',"value" => $phone_alternate),
									  array("name" => 'email1',"value" => $email1),
									  array("name" => 'billing_address_street',"value" => $billing_address_street),
									  array("name" => 'billing_address_city',"value" => $billing_address_city),
									  array("name" => 'billing_address_state',"value" => $billing_address_state),
									  array("name" => 'billing_address_postalcode',"value" => $billing_address_postalcode),
									  array("name" => 'billing_address_country',"value" => $billing_address_country),
									  array("name" => 'shipping_address_street',"value" => $shipping_address_street),
									  array("name" => 'shipping_address_city',"value" => $shipping_address_city),
									  array("name" => "shipping_address_state", "value" => $shipping_address_state),
									  array("name" => "shipping_address_postalcode", "value" => $shipping_address_postalcode),
									  array("name" => "shipping_address_country", "value" => $shipping_address_country),
            						  array("name" => 'description',"value" => $description),
            					      array("name" => 'date_modified',"value" => $date_modified)
            						 )
            				);
			} else {
				$response = $this->proxy->set_entry($this->sess, 'Accounts', 
								array(array("name" => 'name',"value" => $name),
								      array("name" => 'website',"value" => $website),
            					      array("name" => 'ticker_symbol',"value" => $ticker_symbol),
									  array("name" => 'ownership',"value" => $ownership),
									  array("name" => 'industry',"value" => $industry),
									  array("name" => 'account_type',"value" => $account_type),
									  array("name" => 'employees',"value" => $employees),
									  array("name" => 'rating',"value" => $rating),
									  array("name" => 'sic_code',"value" => $sic_code),
									  array("name" => 'annual_revenue',"value" => $annual_revenue),
									  array("name" => 'phone_office',"value" => $phone_office),
									  array("name" => 'phone_fax',"value" => $phone_fax),
									  array("name" => 'phone_alternate',"value" => $phone_alternate),
									  array("name" => 'email1',"value" => $email1),
									  array("name" => 'billing_address_street',"value" => $billing_address_street),
									  array("name" => 'billing_address_city',"value" => $billing_address_city),
									  array("name" => 'billing_address_state',"value" => $billing_address_state),
									  array("name" => 'billing_address_postalcode',"value" => $billing_address_postalcode),
									  array("name" => 'billing_address_country',"value" => $billing_address_country),
									  array("name" => 'shipping_address_street',"value" => $shipping_address_street),
									  array("name" => 'shipping_address_city',"value" => $shipping_address_city),
									  array("name" => "shipping_address_state", "value" => $shipping_address_state),
									  array("name" => "shipping_address_postalcode", "value" => $shipping_address_postalcode),
									  array("name" => "shipping_address_country", "value" => $shipping_address_country),
            						  array("name" => 'description',"value" => $description),
            					      array("name" => 'date_modified',"value" => $date_modified)
									  )
            			);
            }				 
			return $response;
		}
		
	}
$component = new Account($proxy);

$industriesArray = array("" => "",
					   "Apparel" => "Apparel",
					   "Banking" => "Banking",
					   "Biotechnology" => "Biotechnology",
					   "Chemicals" => "Chemicals",
					   "Communications" => "Communications",
					   "Construction" => "Construction",
					   "Consulting" => "Consulting",
					   "Education" => "Education",
					   "Electronics" => "Electronics",
					   "Energy" => "Energy",
					   "Engineering" => "Engineering",
					   "Entertainment" => "Entertainment",
					   "Environmental" => "Environmental",
					   "Finance" => "Finance",
					   "Government" => "Government",
					   "Healthcare" => "Healthcare",
					   "Hospitality" => "Hospitality",
					   "Insurance" => "Insurance",
					   "Machinery" => "Machinery",
					   "Manufacturing" => "Manufacturing",
					   "Media" => "Media",
					   "Not For Profit" => "Not For Profit",
					   "Recreation" => "Recreation",
					   "Retail" => "Retail",
					   "Shipping" => "Shipping",
					   "Technology" => "Technology",
					   "Telecommunications" => "Telecommunications",
					   "Transportation" => "Transportation",
					   "Utilities" => "Utilities",
					   "Other" => "Other");
					   
$accountTypesArray = array ("" => "",
					"Analyst" => "Analyst",
					"Competitor" => "Competitor",
					"Customer" => "Customer",
					"Integrator" => "Integrator",
					"Investor" => "Investor",
					"Partner" => "Partner",
					"Press" => "Press",
					"Prospect" => "Prospect",
					"Reseller" => "Reseller",
					"Other" => "Other");

?>
